/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef OHOS_HMFS_RESIZE_LOAD_H
#define OHOS_HMFS_RESIZE_LOAD_H

#include <iostream>
#include "hmfs_data.h"
#include "hmfs_utils.h"
#include "resize_data.h"
#include "resize_utils.h"
#include "resize_load_sb.h"
#include "resize_load_cp.h"
#include "resize_load_sit.h"
#include "resize_load_nat.h"

namespace OHOS {
namespace Hmfs {
class ResizeLoadSb;
class ResizeLoadCp;
class ResizeLoadSit;
class ResizeLoadNat;
class ResizeLoad{
public:
    ResizeLoad(std::shared_ptr<HmfsConfigData> configPtr, std::shared_ptr<HmfsSbInfo> sbInfoPtr);
    ~ResizeLoad() = default;
    void UpdateSuperBlock(struct SuperBlockData *superBlock, int sbMask);
    int32_t InitSbInfo();
    int32_t HmfsShouldProceed(struct SuperBlockData *sbData, uint32_t flag);
    int32_t UpdateSbFeatures();
	void *GetBitmapPtr(int flag);
    uint32_t GetStartCpAddr();
    uint32_t GetNextFreeBlkAddr(struct CurSegmentInfo * curseg);
    bool HmfsIsValidBlkaddr(uint32_t blkaddr, int type);
    struct FsyncInodeEntry* GetFsyncInode(struct ListNode *head, uint32_t ino);
    struct FsyncInodeEntry* AddFsyncinode(struct ListNode *head, uint32_t ino);
    int32_t FindFsyncInode(struct ListNode *head);
    int32_t HmfsRaMetaPages(uint32_t start, int nrpages, int type);
    int32_t DoRecordFsyncData(struct NodeData *node_blk, uint32_t blkaddr);
    void DelFsyncInode(struct FsyncInodeEntry *entry);
    int32_t TraverseDnodes(struct ListNode *inode_list);
    void DestroyFsyncDnodes(struct ListNode *head);
    int32_t RecordFsyncData(ResizeLoadSit &loadSit);
    int32_t HmfsLoadData();
    void HmfsUnLoadData();
    std::shared_ptr<HmfsConfigData> GetConfig();
	std::shared_ptr<HmfsSbInfo> GetSbInfo();
private:
    std::shared_ptr<HmfsConfigData> config_; /** config */
    std::shared_ptr<HmfsSbInfo> sbInfo_; /** sbi */
};

}
}
#endif
